#!/bin/bash
#
#   This is a  include log template   
#
#

# log level debug-1, info-2, warn-3, error-4
# if log_level = 1 all function is start
LOG_LEVEL=1

# log file
LOG_FILE=./test.log

# debug log
function log_debug() {
    content="$(date '+%Y-%m-%d %H:%M:%S') [DEBUG] $@ "
    [ $LOG_LEVEL -le 1 ] && echo ${content} >> $LOG_FILE && echo  "\033[32m" ${content} "\033[0m"
}

# info log
function log_info() {
    content="$(date '+%Y-%m-%d %H:%M:%S') [INFO] $@ "
    [ $LOG_LEVEL -le 2 ] && echo ${content} >> $LOG_FILE && echo  "\033[32m" ${content} "\033[0m"
}

function log_warn() {
    content="$(date '+%Y-%m-%d %H:%M:%S') [WARNNING] $@ "
    [ $LOG_LEVEL -le 3 ] && echo ${content} >> $LOG_FILE && echo  "\033[33m" ${content} "\033[0m"
}

function log_err() {
    content="$(date '+%Y-%m-%d %H:%M:%S') [ERROR] $@ "
    [ $LOG_LEVEL -le 2 ] && echo ${content} >> $LOG_FILE && echo  "\033[31m" ${content} "\033[0m"
}

log_debug "This is a test debug"
log_info  "This is a test info"
log_warn  "This is a test warnning"
log_err   "This is a test error"
